﻿package net.wangit.jdbc.sqltype;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.sql.Blob;
import java.sql.SQLException;

public class BlobImpl implements Blob {

	private InputStream stream;
	private int length;

	public BlobImpl(String value) {
	}

	public BlobImpl(byte bytes[]) {
		stream = new ByteArrayInputStream(bytes);
		length = bytes.length;
	}

	public BlobImpl(InputStream stream, int length) {
		this.stream = stream;
		this.length = length;
	}

	public long length() throws SQLException {
		return (long) length;
	}

	public void truncate(long pos) throws SQLException {
		excep();
	}

	public byte[] getBytes(long pos, int len) throws SQLException {
		excep();
		return null;
	}

	public int setBytes(long pos, byte bytes[]) throws SQLException {
		excep();
		return 0;
	}

	public int setBytes(long pos, byte bytes[], int i, int j)
			throws SQLException {
		excep();
		return 0;
	}

	public long position(byte bytes[], long pos) throws SQLException {
		excep();
		return 0L;
	}

	public InputStream getBinaryStream() throws SQLException {
		return stream;
	}

	public OutputStream setBinaryStream(long pos) throws SQLException {
		excep();
		return null;
	}

	public long position(Blob blob, long pos) throws SQLException {
		excep();
		return 0L;
	}

	private static void excep() {
		throw new UnsupportedOperationException(
				"Blob may not be manipulated from creating session");
	}

	@Override
	public void free() throws SQLException {
		// TODO Auto-generated method stub
		
	}

	@Override
	public InputStream getBinaryStream(long arg0, long arg1)
			throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}
}
